#include<stdio.h>
#include<string.h>
#include"head.h"
#include<stdlib.h>


void StruToStr(struct student stu, char* str)
{
	char strId[20];
	char strHwScore[20];
	char strTestScore[20];
	char strTotalScore[20];
	char s[2] = "|";
	char se[2] = "\n";
	itoa(stu.i_id, strId, 10);
	gcvt(stu.f_hwGrade, 4, strHwScore);
	gcvt(stu.f_testGrade, 4, strTestScore);
	gcvt(stu.f_totalGrade, 4, strTotalScore);
	strcpy(str, strId);
	strcat(str, s);
	strcat(str, stu.s_Name);
	strcat(str, s);
	strcat(str, stu.s_sex);
	strcat(str, s);
	strcat(str, strHwScore);
	strcat(str, s);
	strcat(str, strTestScore);
	strcat(str, s);
	strcat(str, strTotalScore);
	strcat(str, s);
	strcat(str, stu.from);
	strcat(str, se);
}


void StrToStru(struct student* stu, char *s)
{
	char* p = NULL;
	int i = 0;
	i = strlen(s);
	*(s + i - 1) = '\0';
	p = strtok(s, "|");
	stu->i_id = atoi(p);
	p = strtok(NULL, "|");
	strcpy(stu->s_Name, p);
	p = strtok(NULL, "|");
	strcpy(stu->s_sex, p);
	p = strtok(NULL, "|");
	stu->f_hwGrade = atof(p);
	p = strtok(NULL, "|");
	stu->f_testGrade = atof(p);
	p = strtok(NULL, "|");
	stu->f_totalGrade = atof(p);
	p = strtok(NULL, "|");
	strcpy(stu->from, p);
}
